package com.xpsoft.oa.dao.admin.impl;


import java.math.BigDecimal;

import org.hibernate.Query;

import com.xpsoft.core.dao.impl.BaseDaoImpl;
import com.xpsoft.oa.dao.admin.AdminContractPaymentDao;
import com.xpsoft.oa.model.admin.AdminContractPayment;

public class AdminContractPaymentDaoImpl extends BaseDaoImpl<AdminContractPayment> implements AdminContractPaymentDao{

	public AdminContractPaymentDaoImpl() {
		super(AdminContractPayment.class);
	}

	@Override
	public BigDecimal getPayedByContractId(Long adminContractId) {
		// TODO Auto-generated method stub
		String hql = "select sum(applyAmount) from AdminContractPayment where adminContract.id=:adminContractId";
		Query query = getSession().createQuery(hql);
		Object obj = query.setParameter("adminContractId", adminContractId).uniqueResult();
		BigDecimal payed = new BigDecimal(0);
		if(obj!=null){
			payed = (BigDecimal)obj;
		}
		return payed;
	}

}